/**
 * Created by yuzhang on 2018/4/27.
 */

import React from 'react';
import {Image} from 'react-native';
import face_map from './faces';

const reg = /\[(em_\d*)\]/g

const transform = elementFn => str => {
    if (typeof str !== 'string') {
        console.warn('Need String!')
        return ''
    }
    return str.split(reg).map((item, index) => {
            return face_map[item]
                ? (
                <Image
                key={index}
            source={face_map[item]}
    {...elementFn(face_map[item], index)}
/>
)
: item
})
}

export default transform
